import React, { Component } from 'react';
// import IceContainer from '@icedesign/container';
import { Menu,Nav } from '@icedesign/base';
import { Link, withRouter } from 'react-router-dom';
import './SecondNav.scss';

const { Item } = Nav;

@withRouter
export default class SecondNav extends Component {
  static displayName = 'TabTable';

  static propTypes = {};

  static defaultProps = {};

  constructor(props) {
    super(props);
    // console.log("secondnav",props)
    this.state = {
      tabs: [],
      tabName:'',
      activeKey: localStorage.getItem("sid") ? localStorage.getItem("sid") : "0",
    };
  }

  componentDidMount() {
    this.GetUrlString()
  }

  GetUrlParam(paraName) {
  　var url = document.location.toString();
  　var arrObj = url.split("?");
  　　　if (arrObj.length > 1) {
  　　　　　var arrPara = arrObj[1].split("&");
  　　　　　var arr;
  　　　　　for (var i = 0; i < arrPara.length; i++) {
  　　　　　　　arr = arrPara[i].split("=");
  　　　　　　　if (arr != null && arr[0] == paraName) {
  　　　　　　　　　return arr[1];
  　　　　　　　}
  　　　　　}
  　　　　　return "";
  　　　}
  　　　else { return ""; }
  }

  GetUrlString(paraName) {
    　var url = document.location.toString();
      if(url.indexOf("gdBeta2.0/#/Evaluate/BusinessPerformance")!=-1){
        this.setState({
        activeKey:1
        })
      }else if(url.indexOf("gdBeta2.0/#/Evaluate/FinancialAnalysis")!=-1){
        this.setState({
          activeKey:2
        })
      }else if(url.indexOf("gdBeta2.0/#/Evaluate/PublicOpinion")!=-1){
        this.setState({
          activeKey:4
        })
      }else{
        return "/"
      }
    }

  handleChange = (key) => {
    // console.log("key",key)
    localStorage.setItem("sid",key)
    this.setState({
      activeKey: key,
    });
    if(key=="0"){
      window.location.href=`${global.constants.GOLDEYELOCALHOST}gdBeta2/#/evaluate/xpCompliance?secu_code=${this.GetUrlParam("secu_code")}`
    }else if(key=="1"){
      this.props.history.push(`/Evaluate/BusinessPerformance?secu_code=${this.GetUrlParam("secu_code")}`)
    }else if(key=="2"){
      this.props.history.push(`/Evaluate/FinancialAnalysis?secu_code=${this.GetUrlParam("secu_code")}`)  
    }else if(key=="3"){
      window.location.href = `${global.constants.GOLDEYELOCALHOST}gdBeta2/#/evaluate/marketVolatility?secu_code=${this.GetUrlParam("secu_code")}`
    }else if(key=="4"){
      this.props.history.push(`/Evaluate/PublicOpinion?secu_code=${this.GetUrlParam("secu_code")}`)
    }
  };

  render() {
    return (
      <div className="second-menu">
      <Nav 
        direction="hoz"
        // selectMode="multiple"
        prefix="second"
        // defaultSelectedKeys={[this.state.activeKey]}
        selectedKeys={[`${this.state.activeKey}`]}
        onSelect={this.handleChange.bind(this)}
      >
        <Item prefix="second-" key={0}>
          信披合规
        </Item>

        <Item prefix="second-" key={1}>
          经营绩效
        </Item>
        
        <Item prefix="second-" key={2}>
          财务分析
        </Item>

        <Item prefix="second-" key={3}>
          市场波动
        </Item>

        <Item prefix="second-" key={4}>
          舆情导向
        </Item>
      </Nav>
      </div>
    );
  }
}

